package model

import "errors"

// 先进先出队列
type FIFOQueue struct {
	Size    uint
	MaxSize uint
	Queue   ProjectSlice
}

func (q *FIFOQueue) Empty() bool {
	return q.Size == 0
}

func (q *FIFOQueue) Put(p *Project) error {
	if q.MaxSize == 0 || q.Size < q.MaxSize {
		q.Size += 1
		q.Queue = append(q.Queue, p)
		return nil
	}
	return errors.New("FIFO Queue full")
}

func (q *FIFOQueue) Get() (*Project, error) {
	if q.Size == 0 {
		return &Project{}, errors.New("FIFO Queue empty")
	}
	q.Size -= 1
	v := q.Queue[0]
	q.Queue = q.Queue[1:]
	return v, nil
}
